import { reactive, ref, Ref, watch } from "vue";

// 获取PFMEA表头信息API
import { getTableHeaderInfo } from "@/api/pfmea_file_manage_data";
import { getOpInfo } from "@/api/pfmea_file_manage_data";
import { getPfmeaData } from "@/api/pfmea_file_manage_data";
import { insertPfmeaData } from "@/api/pfmea_file_manage_data";
import { editePfmeaData, deletePfmeaData } from "@/api/pfmea_file_manage_data";

export const TableHeaderInfo = (partName: string, infodata: any) => {
  getTableHeaderInfo(partName).then(res => {
    console.log(res);
    infodata.pfmea_number = res.pfmea_number;
    infodata.partNumber = res.partNumber;
    infodata.partName = res.partName;
    infodata.responsibility = res.responsibility;
    infodata.keyDate = res.keyDate;
    infodata.editDate = res.editDate;
    infodata.editor = res.editor;
    infodata.coreTeam = res.coreTeam;
    infodata.version = res.version;
  });
};

export const OpInfo = (stationList: Ref<String[]>, data?: object) => {
  console.log(data);
  getOpInfo(data).then(res => {
    console.log(res);
    stationList.value = res;
  });
};

export const PfmeaData = (PfmeaDataList: Ref<any>, data?: object) => {
  console.log(data);
  getPfmeaData(data).then(res => {
    console.log(res);
    PfmeaDataList.value = res;
  });
};

export function InsertPfmeaData(data: object) {
  return new Promise((resolve, reject) => {
    insertPfmeaData(data)
      .then(res => {
        console.log(res);
        resolve(res);
      })
      .catch(err => {
        console.log(err);
        reject(err);
      });
  });
}

export function EditePfmeaData(data: object) {
  return new Promise((resolve, reject) => {
    editePfmeaData(data)
      .then(res => {
        console.log(res);
        resolve(res);
      })
      .catch(err => {
        console.log(err);
        reject(err);
      });
  });
}

export function DeletePfmeaData(data: object) {
  return new Promise((resolve, reject) => {
    deletePfmeaData(data)
      .then(res => {
        console.log(res);
        resolve(res);
      })
      .catch(err => {
        console.log(err);
        reject(err);
      });
  });
}
